/**
 * @author yanggjun
 */

PlayMan = {
		pos: {x: 0, y: 400, z: 4500},
		radius: 50,
		height: 400,
		direction: {x: 0, y: 0, z: -1},
		rot: {x:0, y:Math.PI, z: Math.PI,},
		speed: 200,
		jumpHeight: 0,
		curDy: 0,
		jumpDirection: 1,
		score: 0,
		blood: 100,
		move: function(direction){
			var tmpx=0, tmpz=0, tmpRX=0, tmpRZ=0;
			if(direction == "f" ){
				tmpx = this.speed * this.direction.x;
				tmpz = this.speed * this.direction.z;

			}else if(direction == "b"){
				tmpx = -this.speed * this.direction.x;
				tmpz = -this.speed * this.direction.z;
			}else if(direction == "l"){
				tmpx = this.speed * Math.sin(this.rot.y + Math.PI/2);
				tmpz = this.speed * Math.cos(this.rot.y + Math.PI/2);
			}else if(direction = "r"){
				tmpx = this.speed * Math.sin(this.rot.y - Math.PI/2);
				tmpz = this.speed * Math.cos(this.rot.y - Math.PI/2);
	
			}
			tmpRX = this.pos.x + tmpx;
			tmpRZ = this.pos.y + tmpz;
			if(tmpRX < World.floorWidth /2&&
					tmpRX > - World.floorWidth /2){
				this.pos.x = tmpRX;
				TargetIndicator.move(tmpx, 0, 0);
//				console.log("---------------------------");
			}
			tmpRZ = this.pos.z + tmpz;
			if(tmpRZ <  World.floorHeight/2 &&
					tmpRZ > -World.floorHeight/2){
				this.pos.z = tmpRZ;
				TargetIndicator.move(0, 0, tmpz);
			}
			
//			TargetIndicator.move(tmpx, 0, tmpz);
			if(CameraController.isSnipe){
				CameraController.snipe();
			}
			World.camera.position.set(this.pos.x, this.pos.y + this.curDy, this.pos.z);
			Character.updatePosition();

		},
		jump: function(){
			this.jumpHeight = 200;
			this.curDy = 0;
			this.jumpDirection = 1;
		},
		positionYUpdate: function(){
			if(this.jumpHeight > 0){
				if(this.jumpDirection > 0){
					if(this.curDy > this.jumpHeight){
						this.jumpDirection = -1;
					}
				}else{
					if(this.curDy <0 ){
						this.jumpHeight = 0;
						TargetIndicator.move(0,1000+this.pos.y,0);
						return;
					}
				}
				this.curDy += this.jumpDirection*20;			
				World.camera.position.set(this.pos.x, this.pos.y + this.curDy, this.pos.z);
				TargetIndicator.move(0,-1000,0);
			}
		}

}